package com.effect.part1_ObjectCrateDestroy.item5;

import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

/**
 * Created by jon on 17-10-7.
 */

//改进后的Person类只在初始化的时候创建Calendar 、 TimeZone 、Date实例
public class Person_02 {
    private  Date birthDate;
    // Other fields,methods,and constructor omitted

    /**
     * The starting and ending dates of the baby boom.
     */
    private static  Date BOOM_START;
    private static  Date BOOM_END;
    static {
        Calendar gmtCal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
        gmtCal.set(1946, Calendar.JANUARY, 1, 0, 0, 0);
        Date boomStart = gmtCal.getTime();
        gmtCal.set(1965, Calendar.JANUARY, 1, 0, 0, 0);
        Date boomEnd = gmtCal.getTime();
    }

    public  boolean isBabyBoomer(){
      return   birthDate.compareTo(BOOM_START) >= 0 && birthDate.compareTo(BOOM_END) < 0;
    }
}
